<%@ page import="Dao.PostDao" %>
<%@ page import="Vo.Post" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="Dao.CommentDao" %>
<%@ page import="java.util.Set" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="Vo.Comment" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="Vo.User" %><%--
  Created by IntelliJ IDEA.
  User: Cly
  Date: 2021-12-16
  Time: 21:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>帖子</title>
    <link rel="stylesheet" type="text/css" href="主页.css">
</head>
<body>
<%
    User user=(User) session.getAttribute("user");
    String Pid=request.getParameter("Pid");
    PostDao postDao=new PostDao();
    CommentDao commentDao=new CommentDao();
    Post post=new Post();
    HashMap allcomment=new HashMap();
    try {
        post=postDao.getPostbyPid(Pid);
        session.setAttribute("post",post);
        postDao.addhits(Pid);
        allcomment=commentDao.getallcommentbyPid(Pid);
    } catch (Exception e) {
        e.printStackTrace();
    }
%>
<div class="column left">
    <div class="yuan container">
        <h3>欢迎您登录论坛</h3>
        <div class="circle">
            <img src="<%=user.getPic()%>" id="img2" name="img2" height="50px" width="50px"/>
        </div>
        <p><%=user.getUsername()%></p>
        <div id="nav">
            <ul class="firstNav">
                <li>
                    <a href="postMessage.jsp">我要发帖</a>
                </li>
                <li>
                    <a href="change.jsp">修改密码</a>
                </li>
                <li>
                    <a href="login.jsp">注销账户</a>
                </li>
                <li>
                    <a href="home.jsp">返回主页</a>
                </li>
            </ul>
        </div>
    </div>
</div>

<div class="main container">


<div id="title" style="text-align: center">
    <h1><%=post.getTitle()%></h1>
    作者：<%=post.getUsername()%>   访问量：<%=post.getHits()%>    发表时间：<%=post.getCreatedtime()%>
</div>
<hr>
<div id="content" style="text-align: center">
<%=post.getContent()%>
</div>

<hr>
<div id="comments"style="text-align: center">
    <table>
        <tr bgcolor="#808080">
        </tr>
        <%
            Set set=allcomment.keySet();
            Iterator ite=allcomment.keySet().iterator();
            while (ite.hasNext()){
                String Cid=(String) ite.next();
                Comment comment=(Comment) allcomment.get(Cid);
                %>
        <tr>
            <td><%=comment.getUsername()%></td>
            <td><%=comment.getContents()%></td>
            <td><%=comment.getCreatetime()%></td>
        </tr>
        <%}%>
    </table>
</div>
<div id="tocoment">
    <a href="comment.jsp?Pid=<%=post.getPid()%>&&authorID=<%=post.getUid()%>">我要评论</a>
</div>
</div>
</body>
</html>
